var showBindingList = {
	init : function(){
		showBindingList.authorEvent();
		showBindingList.onselectEvent();
		showBindingList.cancelBindEvent();
	},
	/**
	 * 授权
	 */
	author : function(type){
		$.ajax({
			type: "GET",
			url: "/web/bindingAuthor/author?bindingType=" + type,
			dataType: "json",
			success: function(data) {
				if(data && data.url){
					window.location = data.url;
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("网络错误");
			}
		});
	},
	/**
	 * 授权事件
	 */
	authorEvent : function(){
		$("a[id^=bindMyId_]").bind('click',function(){
			var _value = $(this).attr('value');
			showBindingList.author(_value);
		});
	},
	/**
	 * 手风琴事件
	 */
	onselectEvent : function(){
		$("#aa").accordion({
			onSelect : function(title,index){
				var type = $("#aa").accordion('panels')[index].panel('options').id;
				showBindingList.loadBinding(type,index);
			}
		});
	},
	/**
	 * 绑定后页面展现
	 * @param type 类别（新浪微博、腾讯微博、微信）
	 * @param index panel 索引
	 */
	loadBinding : function(type,index){
		$.ajax({
			type: "GET",
			url: "/web/home/getBindingUser?bindingType=" + type,
			dataType: "json",
			success: function(data) {
				if(data && data.userBinding){
					var userBinding = data.userBinding;
					var bindingPanel = $("#aa").accordion('getPanel',index);
					var html = [];
					html.push('<h3 style="color:#0099FF;">');
					html.push(userBinding.bindUserName);
					html.push('</h3>');
					html.push('<a href="#" id="cancleBind_' + type + '" class="easyui-linkbutton" >');
					html.push('取消绑定');
					html.push('</a>');
					html.push('<table id="tt" style="width:800px"></table>');
					bindingPanel.panel({
						content : html.join("")
					});
					
					showBindingList.cancelBindEvent();
				}
				if(data && data.users){
					var users = data.users;
					showBindingList.initInfoTab(users);
				}
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("网络错误");
			}
		});
	},
	cancelBindEvent : function(){
		$("a[id^='cancleBind_']").bind('click',function(){
			var type = this.id.split("cancleBind_")[1];
			showBindingList.cancelBind(type);
		});
	},
	/**
	 * 取消绑定
	 */
	cancelBind : function(type){
		$.ajax({
			type: "GET",
			url: "/web/bindingAuthor/cancelAuthor?bindingType=" + type,
			dataType: "json",
			success: function(data) {
				if(data && data.result && data.result.result == 'true'){
					var id = data.userBinding.id;
					showBindingList.deleteUserBind(id);
					$.messager.alert('提示信息','授权取消成功','success');
				}else{
					$.messager.alert('提示信息','授权取消失败','error');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("网络错误");
			}
		});
	},
	deleteUserBind : function(id){
		$.ajax({
			type: "GET",
			url: "/web/bindingAuthor/deleteUserBinding?id=" + id,
			dataType: "json",
			success: function(data) {
				if(data && data.result){
					
				}else{
					$.messager.alert('提示信息','授权取消失败','error');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("网络错误");
			}
		});
	},
	initInfoTab : function(users){
		var html = [];
		html.push('<div class="bind-info-list ">');
		html.push('	<ul>');
		$.each(users,function(index,data){
			
			html.push('		<li>');
			html.push('<div  style="width:120px;height:15px;background:#fafafa;border:1px solid #ccc">');
			html.push(			data.name);
			html.push('</div>');
			html.push('		</li>');
		});
		html.push('	</ul>');
		html.push('</div>');
		
		$('#tt').tabs({
		    border:false,
		    onSelect:function(title){
		    }
		});
		
		$('#tt').tabs('add',{
		    title:'关注微博',
		    content: html.join(''),
		    closable:true
		});
	},
	initComment : function(){
		
	}
	
};